import flash.events.Event;
import flash.events.EventDispatcher;
import flash.display.DisplayObject;
//import haxe.Math;

class MainCharacterModel extends TileModel
{

  public var exit:Bool;
  public function new
    (
      maxTileSize:Int = 64,
      tileSheetColumn:Int = 0,
      tileSheetRow:Int = 0,
      mapRow:Int = 0, 
      mapColumn:Int = 0, 
      width:Int = 0, 
      height:Int = 0,
      ImageIsSprite:Bool = true,
      ImageHeight = 0,
      ImageWidth = 0,
      ImageX = 0,
      ImageY = 0
    ) 
  {
    super(maxTileSize,tileSheetColumn,tileSheetRow,mapRow,mapColumn,width,height,
	  ImageIsSprite,ImageHeight,ImageWidth,ImageX,ImageY);
  exit = false;
  }

  public override function GetHitBox():SquareModel
  {
      var hitBox = new SquareModel();
      if(MovementState == "LongAttack" || MovementState == "ShortAttack")
      {
	if(direction == "Right")
	{
	 hitBox.xPos = xPos+32; hitBox.yPos=yPos+33;
	 hitBox.width = 30; hitBox.height = 88;
	}
	else
	{
	 hitBox.xPos = xPos+66; hitBox.yPos=yPos+33;
	 hitBox.width = 30; hitBox.height = 88;
	}

      }
      else
      {
	if(direction == "Right")
	{
	hitBox.xPos = xPos+52; hitBox.yPos=yPos+33;
	hitBox.width = 33; hitBox.height = 87;
	}
	else
	{
	  hitBox.xPos= xPos+43; hitBox.yPos=yPos+33;
	  hitBox.width = 33; hitBox.height = 87;
	}
	 
      }
      return hitBox;

  }

  public function GetDirectionOffset():Int
  {
    var offset = 0;
    if(direction == "Left")
    {
	offset = 4;
    }
    else
    {
      offset = 0;
    }
    return offset;
  }

  public override function GetAttackBox():SquareModel
  {

      var hitBox = new SquareModel();
      if(MovementState == "LongAttack" )
      {
	if(direction == "Right")
	{
	hitBox.xPos = xPos+62; hitBox.yPos=yPos+60;
	hitBox.width = 60; hitBox.height = 8;
	}
	else
	{
	  hitBox.xPos = xPos+6; hitBox.yPos=yPos+60;
	  hitBox.width = 60; hitBox.height = 8;
	}
      }
      else if(MovementState == "ShortAttack")
      {
	if(direction == "Right")
	{
	hitBox.xPos = xPos+90; hitBox.yPos=yPos+41;
	hitBox.width = 30; hitBox.height = 43;
	}
	else
	{
	  hitBox.xPos = xPos+8; hitBox.yPos=yPos+41;
	  hitBox.width = 30; hitBox.height = 43;
	}
      }
      else
      {
	hitBox=null;
      }
      return hitBox;
  }

  public override function setTileModel()
  {
    tileSheetColumn = 0;
    tileSheetRow = 0;
  }
  public override function update()
  {
    super.update();
  }
  public function setMovementState()
  {
      if(AttackType == "Long")
      {
	MovementState= "LongAttack";
      }
      else if(AttackType == "Short")
      {
	MovementState= "ShortAttack";
      }
      else if(jumping > 0)
      {
	if(vy < 0 && vy > -2)
	{
	  MovementState = "Jumping";
	}
	if(vy <= -2)
	{
	  MovementState = "JumpingPeak";
	}
	if(vy >= 0)
	{
	  MovementState = "Falling";
	}
      }
      else if(MovementState == "Falling" )
      {
	MovementState = "Land";
      }
      else if(MovementState == "Land" && framesPerState < 4)
      {
	
      }
      else if(vx > 1 || vx < -1 )
      {
	MovementState = "Moving";
      }
      else
      {
	MovementState = "Idle";
      }
  }


}